#include "DataConversion.h"

/* type names:
 *  Ux, Sx: unsigned int (signed int) type with lengh x, eg U16, S16.
 
 *  UxDn, SxDn: float with n digits, eg: U16D1 is U16 / 10.
 */


uint16_t bsToU16(const uint8_t buf[], uint16_t offset) {
    return *((uint16_t *)(buf + offset));
}

float bsToU16D1(const uint8_t buf[], uint16_t offset) {
    return float(*((uint16_t *)(buf + offset))) / 10.0;
}

int16_t bsToS16(const uint8_t buf[], uint16_t offset) {
    return *((int16_t *)(buf + offset));
}

float bsToS16D1(const uint8_t buf[], uint16_t offset) {
    return float(*((int16_t *)(buf + offset))) / 10.0;
}

void U16ToBs(uint8_t buf[], uint16_t value) {
    *((uint16_t *)buf) = value;
}

void U16D1ToBs(uint8_t buf[], float value) {
    *((uint16_t *)buf) = (uint16_t)(value*10.0);
}

void S16ToBs(uint8_t buf[], int16_t value) {
    *((int16_t *)buf) = value;
}

void S16D1ToBs(uint8_t buf[], float value) {
    *((int16_t *)buf) = (int16_t)(value*10.0);
}



